#pragma once
#include<iostream>
#include<arpa/inet.h>
#include<sys/epoll.h>
#include<sys/socket.h>
#include<fcntl.h>
#include<cstring>
#include<unistd.h>
#include<atomic>
#include<thread>
#include<condition_variable>

using namespace std;

class DistributeReactor{
    //listen_socker 监听 负责分发
    //epoll_fd 监控I/O
public:
    DistributeReactor();

    ~DistributeReactor();

    void BeginServer();
private:
    int listen_fd;
    int epoll_fd;
    bool flag;
};


class WorkReactor{
public:
//每一个从reactor对应一个线程，在这个线程内有多个epoll实例，每个线程的epoll实例
//对部分文件描述符进行监听，有事件则处理 
    WorkReactor();
    ~WorkReactor();

   void add(int client_fd,struct sockaddr_in & addr);
   void run();
   int getnums();
    
private:
    atomic<int> nums;
    int epoll_fd;
    bool flag;
};